<template>
  <div class="page">
    <div class="wrap" style="position: sticky;top: 0;z-index: 9;background: #fff;border-top: 1px solid #e6e6e6">
      <div class="" style="height: 70px;padding: 10px 0 10px 10px">
        <div style="display: flex;flex-direction: column;justify-content: space-between;height: 100%;margin-left: 10px;float: left">
          <div>
            <span style="margin-right: 18px;font-weight: bold">{{clueDetail.customer_name}}</span>
          </div>
          <div>
            <i class="el-icon-phone"></i>
            <span style="color: grey;margin-left: 8px">联系电话：</span>
            <span>{{clueDetail.contact}}</span>
          </div>
        </div>

        <div style="float: right;margin-right: 40px;display: flex;align-items: center;height: 100%">
          <!--<el-button size="mini" type="primary" @click="updateDialogShow = true">{{'编辑'}}</el-button>
          <el-button size="mini" type="danger">{{'删除'}}</el-button>-->
          <span style="margin-left: 12px;cursor: pointer;padding: 8px" @click="closeDetailSection">
            <i class="el-icon-close"></i>
          </span>
        </div>
      </div>
      <el-divider style="height: 1px;margin: 0"></el-divider>
    </div>


    <div class="container">

      <div class="section-itemA">
        <div class="itemA">
          <div>跟进人</div>
          <div >
            <el-select style="margin-left: 10px;margin-bottom: 0;" size="mini" filterable v-model="addForm.staff_id" placeholder="跟进人" @change="setCustomerServiceStaff()">
              <el-option v-for="opt in staffList" :key="opt.id" :value="opt.id" :label="opt.realname" />
            </el-select>
          </div>
        </div>
        <div class="itemA">
          <div>微信</div>
          <div style="margin-bottom: 10px">{{ clueDetail.wechat }}</div>
        </div>
      </div>
      <div style="height: 10px;background-color: #EDF1F5;"></div>

      <div class="">
        <div class="content-left">
          <div class="content-panel-list">
            <el-tabs type="border-card" v-model="tabName">
              <el-tab-pane name="infoDetail">
                <span slot="label"><i class="el-icon-date"></i> 详细信息</span>
                <detail_info :clueDetail="clueDetail" />
              </el-tab-pane>
              <el-tab-pane name="flowRecord" label="跟进记录">
                <follow_record :clue_id="clueDetail.id" />
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <!--<div class="content-right">
          <el-tabs type="border-card" v-model="teamTabName">
            <el-tab-pane name="team" label="团队成员">
              <team :clue_id="clueDetail.id" />
            </el-tab-pane>
          </el-tabs>
        </div>-->
      </div>

    </div>
  </div>
</template>

<script>
  import ORIGIN from '../../../assets/json/origin.json'
  import detail_info from "./components/detail_info";
  import follow_record from "./components/follow_record";
  /*import team from "./components/team";*/
  export default {
    name: "clue_detail",
    components: {
      detail_info,
      follow_record
    },
    props: {
      customerDetail: ''
    },
    data() {
      return {
        tabName: 'infoDetail',
        teamTabName: 'team',
        clueDetail: '',
        ORIGIN,
        addressInfo: [[],[],[]],
        addForm: {
          id: '',
          customer_name: '',
          contact: '',
          province: '',
          city: '',
          area: '',
          address: '',
          is_invalid: 1,
          remark: '',
          wechat: '',
          staff_id: ''
        },
        dialogShow: false,
        updateDialogShow: false,
        clueStageList: [],
        staffList: []
      };
    },
    created() {

    },
    mounted() {
      this.getClueDetail(this.customerDetail)
      this.getStaffList()
    },
    methods: {

      async setCustomerServiceStaff() {
        let params = {
          staff_id: this.addForm.staff_id,
          customer_clue_id: this.customerDetail.id
        }
        const res = await this.$api.setCustomerServiceStaff(params)
        if(res.data.level=="success"){
          this.$message.success(res.data.message)
          this.$emit("updateListData")
        } else {
          this.$message.error(res.data.message)
        }
      },

      //获取线索阶段列表数据
      async getStaffList() {
        let params = {
          limit:999,
          page:1,
        }
        const res = await this.$api.getStaffList(params)
        if(res.data.level=="success"){
          this.staffList = res.data.data
        } else {
          this.$message.error(res.data.message)
        }
      },

      //获取详情
      async getClueDetail(data) {
        this.clueDetail = data
        this.addForm.id = data.id
        this.addForm.name = data.name
        this.addForm.contact = data.contact
        this.addForm.email = data.email
        this.addForm.remark = data.remark
        this.addressInfo = [data.province,data.city,data.area]
        this.addForm.clue_stage_id = parseInt(data.clue_stage_id)
        this.addForm.address = data.address
        data.now_staff!=null?this.addForm.staff_id = data.now_staff.id:this.addForm.staff_id = ""
      },

      //获取团队列表
      async getClueTeamList() {
        let params = {
          limit:999,
          page: 1,
          clue_id: this.clueDetail.id
        }
        const res = await this.$api.getClueTeamList(params)
        if(res.data.level=="success"){
          this.teamList = res.data.data
        } else {
          this.$message.error(res.data.message)
        }
      },

      //新增提交按钮
      async addSubmitBtn(){
        this.addForm.province = this.addressInfo[0]
        this.addForm.city = this.addressInfo[1]
        this.addForm.area = this.addressInfo[2]
        const params = this.addForm;
        const res = await this.$api.setClue(params);
        if(res.data.level=='success'){
          this.updateDialogShow = false
          this.$message({
            message: this.addForm.id?'修改成功':'添加成功',
            type: 'success',
          });
          this.getClueDetail(this.$route.query.id)
        }else{
          this.$message({
            message: res.data.message,
            type: 'warning'
          });
        }
      },

      closeDetailSection() {
        this.$emit("closeDetailSection")
      }

    }
  }
</script>

<style scoped>
  .page{
    background: #EDF1F5;
    overflow: hidden;
    height: calc(100vh - 90px);
  }

  .container{
   /* padding: 10px; */
    min-height: 100%;
    background: #EDF1F5;
  }

  .divider{
    width: 100%;
    height: 15px;
    background-color: #EDF1F5;
  }

  /deep/ .wrap .el-divider--horizontal{
    margin: 0;
  }

  .section-itemA{
    background-color: #FFFFFF;
    padding: 10px 0;
    display: flex;
    box-shadow: 0 0 6px #D0DDEA;
    border-radius: 6px;
  }

  .itemA{
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
  }

  .itemA div:first-child{
    color: grey;
    margin-bottom: 10px;
  }

  /deep/ .el-tabs--border-card>.el-tabs__header .el-tabs__item.is-active{
    color: #333333;
    font-weight: bold;
  }
  /deep/ .el-tabs--border-card>.el-tabs__header .el-tabs__item:not(.is-disabled):hover{
    color: #333333;
  }

</style>

<style lang="scss" scoped>
  .section-itemB{
    background-color: #FFFFFF;
    padding: 20px;
    h1{
      font-size: 16px;
      margin-bottom: 12px;
    }
  }

  .content-two{
    display: flex;
    justify-content: space-between;
    .content-left{
      width: 70%;
    }
    .content-right{
      width: 28%
    }
  }

</style>
